from http import HTTPStatus

import pytest
from service import parkings


@pytest.fixture
def parking_json():
    return {
        "address": "Nevskiy pr., 1",
        "opened": True,
        "count_places": 456,
        "count_available_places": 123,
    }


def test_create_parking_route(client, monkeypatch, parking_json):
    mock_id = 456

    def mock_create_parking(address, opened, count_places, count_available_places):
        return {
            "id": mock_id,
            "address": address,
            "opened": opened,
            "count_places": count_places,
            "count_available_places": count_available_places,
        }

    monkeypatch.setattr(parkings, "create_parking", mock_create_parking)

    response = client.post("/parkings/", json=parking_json)
    assert response.status_code == HTTPStatus.CREATED
    assert response.json == {"id": mock_id, **parking_json}
